import os

from flask_migrate import Migrate, MigrateCommand
from flask_script import Manager, Shell, Server

from app import create_app, db, models

app = create_app(os.environ.get('ENV_TYPE', 'development'))


manager = Manager(app)
migrate = Migrate(app, db)


def make_shell_context():
    return dict(
        db=db,
        models=models
    )


manager.add_command('shell', Shell(make_context=make_shell_context))
manager.add_command('db', MigrateCommand)
manager.add_command('runserver', Server(host='0.0.0.0', port=6061))

if __name__ == '__main__':
    manager.run()
